Skip to content

Schedule job for cleanup data #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ynr-ram
Copy link
Contributor

@ynr-ram ynr-ram commented Oct 2, 2024

Overview
This script automates the cleanup of old closed incidents in the ServiceNow instance. It helps maintain a clean and efficient database by removing records that are no longer needed, thereby improving system performance and manageability.

Features
Automatic Cleanup: Deletes closed incidents that are older than 90 days.
Customizable Timeframe: Easily adjustable parameters to change the age of incidents for cleanup.
Logging: Outputs the number of incidents deleted to the system logs for tracking purposes.

Prerequisites
Access to a ServiceNow instance with appropriate permissions to run scripts.
Knowledge of how to create Scheduled Jobs in ServiceNow.

Installation
Create a New Scheduled Job:
Navigate to System Definition > Scheduled Jobs in your ServiceNow instance.
Click on New to create a new Scheduled Job.

Configure the Job:
Name: Enter a descriptive name for the job, e.g., "Cleanup Old Closed Incidents."
Run: Set the desired schedule for when you want the job to run (e.g., daily, weekly).
Script: Copy and paste the provided script into the script section of the Scheduled Job.

ynr-ram added 12 commits October 2, 2022 11:23
This script contains two parts, 1st part is client script and 2nd part is script include.. and this helps to  lock the file till the developer completes his development, so that we can avoid concurrency issues.
Ex: If a "Developer A" working on "Widget A", parallelly if "Developer B" working on "Widget B", then if Developer B moves the code to higher environment before developer A completes his development.. so it creates an issue.. to avoid these kind of concurrency issues.. we can use locking system for each record.. in the above script I shown example for widget records.
Calculate the time difference between incident creation and change implementation
Set due date to incidents based on their priority and the assignment group's working hours
…ty and the assignment group's working hours directory
…creation and related change implementation directory
This script automates the cleanup of old closed incidents in the ServiceNow instance. It helps maintain a clean and efficient database by removing records that are no longer needed, thereby improving system performance and manageability.
This readme file helps to understand what the code exactly going to do.
@snamjosh snamjosh self-assigned this Oct 2, 2024
@snamjosh
Copy link
Contributor

snamjosh commented Oct 2, 2024

@ynr-ram Thanks for your contribution. But, did you consider impact of this script? if closed incidents older than 90 days are deleted, what about cascade delete and records related to these incidents? You may get into broken referenced records. also, this same feature can be completed without code using flow designer.

@Lacah
Copy link
Contributor

Lacah commented Oct 3, 2024

I am closing this following the previous comment, especially considering that the script itself has little added value in its current form. However, if you were to expand your script following for instance Sachin's suggestions, we would be happy to accept it.
You may reopen this PR later or submit a new one, as you see fit.

@Lacah Lacah closed this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants